package com.songlanyun.modules.offlinegoods.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.songlanyun.common.drive.RootEntity;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 线下商品
 *
 * @author lijiahe
 * @date 2023-02-11
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("yxt_offline_goods")
public class OfflineGoods extends RootEntity<Long, OfflineGoods> implements Serializable {
    private static final long serialVersionUID = 1L;

    {
        price = BigDecimal.ZERO;
        originalPrice = BigDecimal.ZERO;
        isUp = 0;
    }

    /**
     * 服务商品id
     */
    @TableId
    private Long id;
    /**
     * 商家id
     */
    private Long shopId;
    /**
     * 分类id
     */
    private Long typeId;
    /**
     * 所属类型 0商品 1服务
     */
    private Integer type;
    /**
     * 商品名称
     */
    private String name;
    /**
     * 售价
     */
    private BigDecimal price;
    /**
     * 原价
     */
    private BigDecimal originalPrice;
    /**
     * 图片
     */
    private String img;
    /**
     * 详情
     */
    private String details;

    /**
     * 详情图片(最多6张)
     */
    private String detailsImg;
    @TableField(exist = false)
    private List<String> detailsImages;

    public List<String> getDetailsImages() {
        if (ObjectUtil.isNotNull(detailsImg)) {
           return detailsImages = JSONArray.parseArray(detailsImg, String.class);
        } else {
            return null;
        }
    }

    public void setDetailsImages(List<String> detailsImages) {
        this.detailsImages = detailsImages;
        if (!detailsImages.isEmpty()) {
            this.detailsImg = JSONUtil.toJsonStr(this.detailsImages);
        }
    }

    /**
     * 是否上架 0否 1是
     */
    private Integer isUp;

    /**
     * 销量
     */
    private Integer salesVolume;

    /**
     * 创建者
     */
    private Long createBy;

    @TableField(fill = FieldFill.INSERT)
    private Date createTime;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    @Override
    public Long getIdentity() {
        return id;
    }
}
